//! 配置管理模块
//! 定义系统常量、配置项和错误码

use hex_literal::hex as hex_l;

/// 系统配置常量
pub struct Config {
    /// 默认加密密钥
    pub default_key: Vec<u8>,
    /// 服务器监听地址
    pub server_address: String,
    /// 服务器端口
    pub server_port: u16,
    /// 默认PIN
    pub default_pin: String,
}

impl Default for Config {
    fn default() -> Self {
        Self {
            default_key: hex_l!("e0f4543f3e2a2c5ffc7e5e5a222e3e4d").to_vec(),
            server_address: "127.0.0.1".to_string(),
            server_port: 6666,
            default_pin: "1234".to_string(),
        }
    }
}

/// 消息类型常量
pub mod message_types {
    pub const AUTH_REQUEST: &str = "1100";
    pub const AUTH_RESPONSE: &str = "1110";
    pub const REVERSAL_REQUEST: &str = "1420";
    pub const REVERSAL_RESPONSE: &str = "1430";
}

/// 响应码常量
pub mod response_codes {
    pub const APPROVED: &str = "000";
    pub const DECLINED_AMOUNT: &str = "100";
    pub const INVALID_AMOUNT: &str = "107";
    pub const MISSING_AMOUNT: &str = "115";
    pub const PIN_VERIFICATION_FAILED: &str = "117";
    pub const PIN_PROCESSING_ERROR: &str = "126";
    pub const MAC_VERIFICATION_FAILED: &str = "916";
    pub const REVERSAL_DECLINED: &str = "400";
}

/// 字段编号常量
pub mod field_numbers {
    pub const PAN: u8 = 2;
    pub const PROCESSING_CODE: u8 = 3;
    pub const AMOUNT: u8 = 4;
    pub const STAN: u8 = 11;
    pub const EXPIRY_DATE: u8 = 14;
    pub const COUNTRY_CODE: u8 = 19;
    pub const APPROVAL_CODE: u8 = 38;
    pub const RESPONSE_CODE: u8 = 39;
    pub const PIN_DATA: u8 = 52;
    pub const ADDITIONAL_DATA_1: u8 = 61;
    pub const ADDITIONAL_DATA_2: u8 = 62;
    pub const ADDITIONAL_DATA_3: u8 = 63;
    pub const MAC_PRIMARY: u8 = 64;
    pub const ADDITIONAL_AMOUNTS: u8 = 96;
    pub const MAC_SECONDARY: u8 = 128;
    pub const PRIVATE_DATA: u8 = 160;
}

/// 业务规则常量
pub mod business_rules {
    pub const AMOUNT_THRESHOLD: u32 = 100;
    pub const APPROVAL_CODE: &str = "APPR01";
    pub const ADDITIONAL_DATA_SUFFIX: &str = "-OK";
    pub const DEFAULT_ADDITIONAL_DATA_3: &str = "007";
    pub const DEFAULT_PRIVATE_DATA: &str = "F160";
}

/// 默认PIN常量
pub const DEFAULT_PIN: &str = "1234";

/// 需要回显的字段
pub const ECHO_FIELDS: &[u8] = &[2, 3, 4, 11, 14, 19, 96];